package com.longjianghuasheng.logistics.business.address.adapter

import android.annotation.SuppressLint
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.longjianghuasheng.logistics.R
import com.longjianghuasheng.logistics.databinding.ItemAddressBinding
import com.longjianghuasheng.logistics.entity.AddressResponse

class AddressAdapter :
    BaseQuickAdapter<AddressResponse, BaseDataBindingHolder<ItemAddressBinding>>(R.layout.item_address) {
    var onCheckListener = { id: Int, isChecked: Boolean ->

    }

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseDataBindingHolder<ItemAddressBinding>, item: AddressResponse) {
        holder.dataBinding?.run {
            tvName.text = "${item.names},${item.mobile}"
            tvAddress.text = item.run { province + city + area + address }
            cbDefault.isChecked = item.is_default == 1
            cbDefault.setOnCheckedChangeListener { buttonView, isChecked ->
                if (!buttonView.isPressed) return@setOnCheckedChangeListener
                onCheckListener.invoke(item.id, isChecked)
            }
        }
    }
}